package com.hzcc.tagmanagesystemapi.module.controller;

import com.hzcc.tagmanagesystemapi.common.ResultResponse;
import com.hzcc.tagmanagesystemapi.common.enums.ApiFileEnums;
import com.hzcc.tagmanagesystemapi.module.entity.po.ApiFile;
import com.hzcc.tagmanagesystemapi.module.entity.po.ApiName;
import com.hzcc.tagmanagesystemapi.module.service.ApiFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;
import java.util.List;

/**
 * @Author 早睡蛋
 * @Date 2022/5/22 13:58:32
 * @Desc:文档controller层
 */

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/api/apiFile")
@Api(value = "api接口文档管理")
public class ApiFileController {

    @Autowired
    private ApiFileService apiFileService;

    /**
     *添加
     * @param apiFile
     * @return
     */
    @PostMapping("/addApiFile")
    @ApiOperation("添加文档接口")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功", response = ResultResponse.class),
            @ApiResponse(code = 400, message = "失败", response = ResultResponse.class),
    })
    public ResultResponse addApiFile(@RequestBody ApiFile apiFile){
        return apiFileService.addApiFile(apiFile);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("deleteApiFile")
    @ResponseBody
    @ApiOperation("删除文档接口")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功", response = ResultResponse.class),
            @ApiResponse(code = 400, message = "失败", response = ResultResponse.class),
    })
    public ResultResponse deleteApiFile(String id){
        return apiFileService.deleteApiFile(id);
    }

    /**
     * 更新
     * @param apiFile
     * @return
     */
    @PostMapping("/updateApiFile")
    @ApiOperation("更新文档接口")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功", response = ResultResponse.class),
            @ApiResponse(code = 400, message = "失败", response = ResultResponse.class),
    })
    public ResultResponse updateApiFile(@RequestBody ApiFile apiFile) throws ParseException {
        return apiFileService.updateApiFile(apiFile);
    }

    /**
     * 查询所有接口
     * @return
     */
    @GetMapping("/allApiName")
    @ApiOperation("查询所有接口")
    public List<ApiName> allApiName(){
        return apiFileService.allApiName();
    }

    /**
     * 通过id查询接口文档
     * @param id
     * @return
     */
    @GetMapping("/oneApiFile")
    @ApiOperation("通过id获取接口文档")
    public ResultResponse oneApiFile(String id){
        ApiFile apiFile = apiFileService.oneApiFile(id);
        return ApiFileEnums.OK.getResultResponse().data("data",apiFile);
    }

}
